
//
//  LYFMainTabBarController.swift
//  weibohhhh
//
//  Created by fersh on 16/1/2.
//  Copyright © 2016年 fersh. All rights reserved.
//

import UIKit

class LYFMainTabBarController: UITabBarController {
   

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = LYFTabBar()
        
        tabbar.composeButtonClickBlock = {
        
            //print("被点击了")

        }
//        setValue(tabbar, forKey: "tabBar")
        setValue(tabbar, forKeyPath: "tabBar")
        //添加子控制器
        addChildViewControllers()
        
    }
    func  addChildViewControllers() {
        
      addChildViewController(LYFHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        
      addChildViewController(LYFMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        
      addChildViewController(LYFDiscoveryTableViewController(), imageName: "tabbar_discover", title: "发现")
        
      addChildViewController(LYFProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    
    }
    
    func addChildViewController(vc: UIViewController,imageName: String,title: String) {
        
//        vc.navigationItem.title = title
//        vc.tabBarItem.title = title
        vc.title = title
        //设置不同状态的图片
        vc.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置选中状态下的文字的颜色
        let dict = [NSForegroundColorAttributeName: UIColor.orangeColor()]
        
        vc.tabBarItem.setTitleTextAttributes(dict, forState: UIControlState.Selected)
        //添加子控制器
        addChildViewController(LYFNavigationController(rootViewController: vc))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
       
    }
    


}
